Vue.component("upload-images", {
  template: `<el-upload class="upload-demo" :show-file-list="false" accept="image/*" drag :on-change="upload" :auto-upload="false" action="" multiple>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">
            只能上传jpg/png文件
            <el-slider :min="1" v-model="quality" :format-tooltip="formatTooltip"></el-slider>
            <div v-show="quality < 100">当前图片压缩至{{quality}}%</div>
        </div>
    </el-upload>
    `,
  props: ["data"],
  data() {
    return {
      quality: 100,
    };
  },
  methods: {
    formatTooltip(val) {
      return "图片压缩比例：" + val + "%";
    },
    upload({ raw }) {
      const that = this;
      new Compressor(raw, {
        quality: that.quality / 100,
        success(file) {
          const isJPGorPNG =
            file.type === "image/jpeg" || file.type === "image/png";
          const isLt500K = file.size / 1024 / 1024 < 10; // 500KB
          if (!isJPGorPNG) {
            that.$message({
              message: "上传头像图片只能是 JPG/PNG 格式!",
              type: "warning",
            });
            return false;
          }
          if (!isLt500K) {
            that.$message({
              message: "上传图片大小不能超过 10MB! 可压缩后上传",
              type: "warning",
            });
            return false;
          }
          const formData = new FormData();
          formData.append("file", file, file.name);
          let oFileReader = new FileReader();
          oFileReader.readAsDataURL(file);
          oFileReader.onload = function (e) {
            $.ajax({
              headers: requestHeaders("JSON"),
              url: `${BASE_URL2}/generalBusiness/generalSaveFilesAsImage`,
              type: "POST",
              data: JSON.stringify({
                Data: e.target.result,
                DataLength: file.size,
                FileName: file.name,
              }),
              complete: function (XMLHttpRequest) {
                requestPretreatment(XMLHttpRequest);
              },
              success: function (Result) {
                if (Result.Status == "success") {
                  that.$message.success("上传成功");
                  that.data.push({
                    Base64: e.target.result,
                    Picture_URL: Result.FileName,
                    Picture_Type: 0,
                  });
                } else {
                  that.$message.error("上传失败");
                }
              },
              error: function () {
                // that.$message.error("操作失败，请稍后再试");
              },
              dataType: "json",
            });
          };
        },
      });
    },
  },
});
Vue.component("yl-upload1", {
  template: `<div>
    <div class="preview" style="width:100px;height:100px" v-if="Picture_URL">
        <el-image class="el-upload-list__item-thumbnail" style="width: 100px; height: 100px" :src="base64?Picture_URL:base + Picture_URL" fit="contain"></el-image>
        <span class="el-upload-list__item-actions" style="width:100px;height:100px">
            <span @click="handlePictureCardPreview(base64?Picture_URL:base + Picture_URL)"><i class="el-icon-zoom-in"></i></span>
            <span @click="handleRemove"><i class="el-icon-delete"></i></span>
        </span>
    </div>
    <el-upload id="group" :disabled="loading" v-else class="upload-demo" :show-file-list="false" :on-change="upload"
        list-type="picture-card" action="" accept="image/*" :auto-upload="false">
        <i slot="default" :class="loading?'el-icon-loading':'el-icon-plus'"></i>
        <div v-if="!unslider" class="el-upload__tip" slot="tip">
            <div v-show="quality < 100">当前图片压缩至{{quality}}%</div>
            <el-slider :min="1" style="width:148px" v-model="quality" :format-tooltip="formatTooltip"></el-slider>
        </div>
    </el-upload>
    <el-dialog :visible.sync="dialogVisible">
      <el-image width="100%" fit="contain" :src="dialogImageUrl">
    </el-dialog></div>`,
  props: {
    value: {
      type: String,
      default: "",
    },
    base: {
      type: String,
      default: "",
    },
    base64: {
      type: Boolean,
      default: false,
    },
    unslider: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      Picture_URL: this.value,
      loading: false,
      dialogVisible: false,
      dialogImageUrl: "",
      quality: 100,
    };
  },
  watch: {
    value(newVal) {
      this.Picture_URL = newVal;
    },
    Picture_URL(newVal) {
      this.$emit("input", newVal);
    },
  },
  methods: {
    formatTooltip(val) {
      return "图片压缩比例：" + val + "%";
    },
    upload({ raw }) {
      const that = this;
      new Compressor(raw, {
        quality: that.quality / 100,
        success(file) {
          that.loading = true;
          const formData = new FormData();
          formData.append("file", file, file.name);
          let oFileReader = new FileReader();
          oFileReader.readAsDataURL(file);
          oFileReader.onload = function (e) {
            if (!that.base64) {
              $.ajax({
                headers: requestHeaders("JSON"),
                url: `${BASE_URL2}/generalBusiness/generalSaveFilesAsImage`,
                type: "POST",
                data: JSON.stringify({
                  Data: e.target.result,
                  DataLength: file.size,
                  FileName: file.name,
                }),
                success: function (Result) {
                  if (Result.Status == "success") {
                    that.Picture_URL = Result.FileName;
                    that.$message.success("上传成功");
                  } else {
                    that.$message.error("上传失败");
                  }
                },
                complete: function (XMLHttpRequest) {
                  that.loading = false;
                  requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
              });
            } else {
              that.Picture_URL = e.target.result;
              that.loading = false;
            }
          };
        },
        error(err) {
          console.log(err.message);
        },
      });
    },
    handlePictureCardPreview(Val) {
      this.dialogVisible = true;
      this.dialogImageUrl = Val;
    },
    handleRemove() {
      this.Picture_URL = "";
    },
  },
});
new Vue({
  el: "#app",
  data() {
    return {
      category: [], //类别
      is_Article_Type: "", // 包装信息
      is_Unit_Price: "",
      is_JDCOM_Unit_Price: "",
      bzdw: [
        {
          value: "箱",
          label: "箱",
        },
        {
          value: "瓶",
          label: "瓶",
        },
      ],
      article_info: [
        {
          value: "预包装",
          label: "预包装",
        },
      ], //包装信息
      VarietyID: "",
      GradeID: "",
      iJSONArray_Variety: [],
      iJSONArray_VarietyGrade: [],
      form: {
        Article_SerialNumber: "", //商品主键
        Article_Name: "", //商品名称
        Article_Code: "",
        Staples_Code: "",
        Brand_SerialNumber: "", //商品品牌
        Category_SerialNumber: "", //商品类别
        Series_SerialNumber: "", //商品系列
        Item_SerialNumber: "", //商品款型
        Unit_Price: 0, //吊牌价
        Picture_URL: "", //封面图
        Unify_Unit_Price: "0",
        ClassifyJSON: "",
        JDCOM_Unit_Price: "",
        JDCOM_URL: "",
        Group: "否",
        Children: {
          business_article_specifications: [
            {
              Article_Specifications_SerialNumber: "", //规格主键
              Article_SerialNumber: "",
              Specifications_Name: "", //规格名称
              Unit_Price: 0, //吊牌价
              SKU_Quantity: "", //SKU数量
              Centralize_Purchase_Price: "",
              Picture_URL: "", //规格图片
              Size: "",
              Weight: "", //重量
              Weight_Unit: "", //单位
              JDCOM_Unit_Price: "", //吊牌价
              JDCOM_URL: "", //京东路径
              Package_Quantity: "", //包装数量
              SKU_Package_Size: "", //包装尺寸
              Carton_Quantity: "", //大包装数量
              Children_Specifications_SerialNumber: "",
              Other: [
                {
                  Supplier_SerialNumber: "",
                  Sales_Unit_Price: "",
                  Purchase_Unit_Price: "",
                  Quantity: "",
                  Pionts: [],
                  Deduction_Type: "1",
                  Deduction_Limit: "100",
                  Activity: [
                    {
                      Activity_SerialNumber: "",
                      Activity_Unit_Price: "",
                    },
                  ],
                },
              ],
            },
          ],
          business_article_pic: [], //商品图片
          business_article_classify: [],
        },
      },
      rules: {
        Article_Name: [
          { required: true, message: "请输入商品名称", trigger: "blur" },
        ],
        Brand_SerialNumber: [
          { required: true, message: "请选择商品品牌", trigger: "change" },
        ],
        // Unit_Price: [{ required: true, message: '请输入商品吊牌价', trigger: 'change' }],
        Specifications_Name: [
          { required: true, message: "请输入规格名称", trigger: "blur" },
        ],
        // SKU_Quantity: [{ required: true, message: '请输入SKU数量', trigger: 'blur' }]
      },
      activeName: "",
      Main_Image: [],
      Detail_Image: [],
      brand: [], //品牌
      category: [], //类别
      series: [], //系列
      item: [], //款型
      unit: [], //单位
      supplier: [], //供应商
      activity: [], //活动
      classify: [],
      business_article_classify: [],
      defaultProps: {
        children: "Children",
        label: "Classify_Name",
        value: "Classify_SerialNumber",
        multiple: true,
      },
      loading: false,
      isMainSort: false, //主图排序
      isDetailSort: false, //详情图排序
      MainSortable: null, //主图拖拽
      DetailSortable: null, //详情图拖拽
      business_article_group: [], //存放商品规则组
      business_article_specifications: [], //存放最开始获取的规格
    };
  },
  mounted() {
    const Article_SerialNumber = sessionStorage.getItem("Article_SerialNumber");
    this.getData(Article_SerialNumber);
    this.sortable(
      this,
      "#Main_Image",
      ".preview",
      "Main_Image",
      "MainSortable"
    );
    this.sortable(
      this,
      "#Detail_Image",
      ".preview",
      "Detail_Image",
      "DetailSortable"
    );
  },
  computed: {
    is() {
      return function (i, item) {
        //判断当前规格是否可当子规格
        try {
          let b1 = i.Row_Status != "1", //没被删
            b2 = i.Article_Specifications_SerialNumber != "", //已存在
            b3 =
              i.Article_Specifications_SerialNumber !=
              item.Article_Specifications_SerialNumber; //不是自己
          return b1 && b2 && b3;
        } catch (error) {
          return false;
        }
      };
    },
    business_supplier_article() {
      let business_supplier_article = [];
      this.form.Children.business_article_specifications.forEach((item) => {
        item.Other.filter((i) => i.Supplier_SerialNumber).forEach((ite) => {
          business_supplier_article.push({
            Supplier_Article_SerialNumber: ite.Supplier_Article_SerialNumber
              ? ite.Supplier_Article_SerialNumber
              : "",
            Article_Name: this.form.Article_Name,
            Specifications_Name: item.Specifications_Name,
            Brand_SerialNumber: this.form.Brand_SerialNumber,
            Supplier_SerialNumber: ite.Supplier_SerialNumber,
            Article_SerialNumber: "",
            Article_Specifications_SerialNumber:
              ite.Article_Specifications_SerialNumber
                ? ite.Article_Specifications_SerialNumber
                : "",
            Shelf: "1",
            Sales_Unit_Price: ite.Sales_Unit_Price,
            Purchase_Unit_Price: ite.Purchase_Unit_Price,
            Quantity: ite.Quantity,
            Pionts: ite.Pionts,
            Deduction_Type: ite.Deduction_Type,
            Deduction_Limit: ite.Deduction_Limit,
            Activity: ite.Activity,
            isModify: ite.isModify ? true : false,
          });
        });
      });
      return business_supplier_article;
    },
  },
  watch: {
    isMainSort(val) {
      this.MainSortable.option("disabled", !val);
    },
    isDetailSort(val) {
      this.DetailSortable.option("disabled", !val);
    },
    "form.Unit_Price": function (val) {
      if (this.form.Unify_Unit_Price == "1") {
        this.form.Children.business_article_specifications.forEach((item) => {
          item.Unit_Price = val;
        });
      }
    },
    "form.Unify_Unit_Price": function (val) {
      if (val == "1") {
        this.form.Children.business_article_specifications.forEach((item) => {
          item.Unit_Price = this.form.Unit_Price;
        });
      }
    },
    business_article_group: {
      handler(newVal) {
        let arr = [];
        newVal.forEach((item, index) => {
          let business_article_group_detail =
            item.Children.business_article_group_detail.filter(
              (i, id) =>
                ((index == 0 && id == 0) ||
                  i.Specification_Group_Detail_Name) &&
                item.Row_Status != "1"
            );
          if (business_article_group_detail.length > 0) {
            arr.push(business_article_group_detail);
          }
        });
        //计算笛卡尔积
        arr = cartesianProduct(arr);
        let business_article_specifications = [];
        arr.forEach((item) => {
          let obj = this.form.Children.business_article_specifications.filter(
            (i) => i.Group_ID == JSON.stringify(item.map((obj) => obj.id))
          )[0];
          if (obj) {
            business_article_specifications.push({
              ...obj,
              Specifications_Name: item
                .map((obj) => obj.Specification_Group_Detail_Name)
                .join("-"),
            });
          } else {
            business_article_specifications.push({
              Article_Specifications_SerialNumber: "", //规格主键
              Article_SerialNumber: "",
              Specifications_Name: item
                .map((obj) => obj.Specification_Group_Detail_Name)
                .join("-"), //规格名称
              Group_ID: JSON.stringify(item.map((obj) => obj.id)),
              Centralize_Purchase_Price: "",
              Unit_Price: "", //吊牌价
              SKU_Quantity: "", //SKU数量
              Size: "",
              Weight: "", //重量
              Weight_Unit: "", //单位
              JDCOM_Unit_Price: "",
              JDCOM_URL: "",
              Package_Quantity: "", //包装数量
              SKU_Package_Size: "", //包装尺寸
              Carton_Quantity: "", //大包装数量
              Children_Specifications_SerialNumber: "",
              Other: [
                {
                  Supplier_SerialNumber: "",
                  Sales_Unit_Price: "",
                  Purchase_Unit_Price: "",
                  Quantity: "",
                  Pionts: [],
                  Deduction_Type: "1",
                  Deduction_Limit: "100",
                  Activity: [
                    {
                      Activity_SerialNumber: "",
                      Activity_Unit_Price: "",
                    },
                  ],
                },
              ],
            });
          }
        });
        this.form.Children.business_article_specifications =
          business_article_specifications;
      },
      deep: true,
    },
  },
  methods: {
    handleChange(value) {
      console.log(value, "value");

      // return;
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableName",
        type: "POST",
        data: {
          Data: "base_EdibleMushroomGrade",
          Condition: "Row_Status='0' AND VarietyID='" + _this.VarietyID + "'",
        },
        success: function (Result) {
          // _this.tableData = Result.Rows;
          _this.iJSONArray_VarietyGrade = new Array(); //清空数组中原有值
          _this.iJSONArray_VarietyGrade = Result;
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    getData(DocumentSerialNumber) {
      const that = this;
      const Condition = "";
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
        type: "POST",
        data: {
          Data: "business_brand",
          Condition,
        },
        success: function (res) {
          that.brand = res;
        },
        complete: function (XMLHttpRequest) {
          that.loading = false;
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
        type: "POST",
        data: {
          Data: "business_category",
          Condition,
        },
        success: function (res) {
          that.category = res;
        },
        complete: function (XMLHttpRequest) {
          that.loading = false;
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
        type: "POST",
        data: {
          Data: "business_series",
          Condition,
        },
        success: function (res) {
          that.series = res;
        },
        complete: function (XMLHttpRequest) {
          that.loading = false;
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
        type: "POST",
        data: {
          Data: "business_item",
          Condition,
        },
        success: function (res) {
          that.item = res;
        },
        complete: function (XMLHttpRequest) {
          that.loading = false;
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
        type: "POST",
        data: {
          Data: "business_supplier_info",
          Condition,
        },
        success: function (res) {
          that.supplier = res;
        },
        error: function () {
          //   that.$message.error("操作失败，请稍后再试");
        },
        complete: function (XMLHttpRequest) {
          that.loading = false;
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
        type: "POST",
        data: {
          Data: "business_article_unit",
          Condition,
        },
        success: function (res) {
          that.unit = res;
        },
        complete: function (XMLHttpRequest) {
          that.loading = false;
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/getAllClassify`,
        type: "GET",
        success: function (data) {
          that.classify = data;
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
        type: "POST",
        data: {
          Data: "business_activity",
          Condition: "Row_Status <> '1' AND End_Date > NOW()",
        },
        success: function (res) {
          that.activity = res;
        },
        error: function () {
          //   that.$message.error("操作失败，请稍后再试");
        },
        complete: function (XMLHttpRequest) {
          that.loading = false;
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
      $.ajax({
        url: `${BASE_URL1}/getSubtableInquiryOriginal?grant_type=tourist`,
        type: "POST",
        data: {
          Primary_Key: DocumentSerialNumber,
          JSONObject: JSON.stringify({
            business_article_info: {
              business_article_pic: {},
              business_article_specifications: {},
              business_article_classify: {},
              business_article_group: {
                business_article_group_detail: {},
              },
            },
          }),
          Condition: "Row_Status <> '1'",
        },
        success: function ({ business_article_info }) {
          if (business_article_info.length == 1) {
            if (business_article_info[0].ClassifyJSON) {
              that.business_article_classify =
                business_article_info[0].ClassifyJSON;
            }
            //1.将规格组定编号
            business_article_info[0].Children.business_article_group.forEach(
              (item) => {
                item.Children.business_article_group_detail.forEach((ite) => {
                  ite.id = createUniqueString();
                });
              }
            );
            //2.规格组转化称笛卡尔积格式
            let arr = [];
            business_article_info[0].Children.business_article_group.forEach(
              (item, index) => {
                let business_article_group_detail =
                  item.Children.business_article_group_detail.filter(
                    (i, id) =>
                      (index == 0 && id == 0) ||
                      i.Specification_Group_Detail_Name
                  );
                if (business_article_group_detail.length > 0) {
                  arr.push(business_article_group_detail);
                }
              }
            );
            arr = cartesianProduct(arr);
            //3.根据笛卡尔积规格名称组合，查询对应规格，赋值编号组
            arr.forEach((item) => {
              let obj =
                business_article_info[0].Children.business_article_specifications.filter(
                  (i) =>
                    i.Specifications_Name ==
                    item
                      .map((obj) => obj.Specification_Group_Detail_Name)
                      .join("-")
                )[0];
              if (obj) {
                obj.Group_ID = JSON.stringify(item.map((obj) => obj.id));
              }
            });
            business_article_info[0].Children.business_article_pic.forEach(
              (item) => {
                if (item.Picture_Type == "0") {
                  //主图
                  that.Main_Image.push(item);
                } else {
                  //详情图
                  that.Detail_Image.push(item);
                }
              }
            );
            that.activeName = 0;
            business_article_info[0].Children.business_article_specifications.forEach(
              (item) => {
                item.Other = [];
              }
            );
            //冒泡排序
            sort(that.Main_Image, "Picture_Order");
            sort(that.Detail_Image, "Picture_Order");
            //操作
            //1.查询
            $.ajax({
              headers: requestHeaders(),
              type: "POST",
              url: `${BASE_URL2}/generalBusiness/generalQueryBySQLSerialNumber`,
              data: {
                SQLSerialNumber: "A_business_article_info3",
                Condition: window.btoa(
                  unescape(
                    encodeURIComponent(
                      business_article_info[0].Article_SerialNumber
                    )
                  )
                ),
                ExtensionCondition: "",
              },
              success: function (Result) {
                let Other = [];
                console.log(Result);
                Result.forEach((item) => {
                  let obj = Other.filter(
                    (i) =>
                      i.Article_Specifications_SerialNumber ==
                      item.Article_Specifications_SerialNumber
                  )[0];
                  if (obj) {
                    obj.Activity.push({
                      Activity_Article_SerialNumber:
                        item.Activity_Article_SerialNumber,
                      Activity_Article_SerialNumber_Original:
                        item.Activity_Article_SerialNumber,
                      Activity_SerialNumber: item.Activity_SerialNumber,
                      Activity_SerialNumber_Original:
                        item.Activity_SerialNumber,
                      Activity_Unit_Price: item.Activity_Unit_Price,
                      Activity_Unit_Price_Original: item.Activity_Unit_Price,
                    });
                  } else {
                    Other.push({
                      ...item,
                      Activity: [
                        {
                          Activity_Article_SerialNumber:
                            item.Activity_Article_SerialNumber,
                          Activity_Article_SerialNumber_Original:
                            item.Activity_Article_SerialNumber,
                          Activity_SerialNumber: item.Activity_SerialNumber,
                          Activity_SerialNumber_Original:
                            item.Activity_SerialNumber,
                          Activity_Unit_Price: item.Activity_Unit_Price,
                          Activity_Unit_Price_Original:
                            item.Activity_Unit_Price,
                        },
                      ],
                    });
                  }
                });
                Other.forEach((item) => {
                  business_article_info[0].Children.business_article_specifications
                    .filter(
                      (i) =>
                        i.Article_Specifications_SerialNumber ==
                        item.Article_Specifications_SerialNumber
                    )[0]
                    .Other.push({
                      Supplier_Article_SerialNumber:
                        item.Supplier_Article_SerialNumber,
                      Supplier_SerialNumber: item.Supplier_SerialNumber,
                      Article_Specifications_SerialNumber:
                        item.Article_Specifications_SerialNumber,
                      Sales_Unit_Price: item.Sales_Unit_Price,
                      Purchase_Unit_Price: item.Purchase_Unit_Price,
                      Quantity: item.Total_stock,
                      Pionts: item.Cash_Point == "0" ? ["Cash"] : [],
                      Deduction_Type: item.Deduction_Type,
                      Deduction_Limit: item.Deduction_Limit,
                      Activity: item.Activity,
                      isModify: true,
                    });
                });
                that.form = business_article_info[0];
                that.business_article_group =
                  business_article_info[0].Children.business_article_group;
                that.business_article_specifications =
                  business_article_info[0].Children.business_article_specifications;
              },
              complete: function (XMLHttpRequest) {
                requestPretreatment(XMLHttpRequest);
              },
              dataType: "json",
            });
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    submitForm(formName) {
      const that = this;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          that.loading = true;
          //将不存在的图片删除
          that.Main_Image.filter((i) => i.Row_Status != "1").forEach(
            (item, index) => {
              //主图
              if (
                !Object.keys(item).some((item) => item.includes("_Original"))
              ) {
                //新图片
                that.form.Children.business_article_pic.push({
                  Article_PicNumber: "",
                  Article_SerialNumber: that.form.Article_SerialNumber,
                  Picture_Type: "0",
                  Picture_Order: index + 1,
                  Picture_URL: item.Picture_URL,
                });
              } else {
                //老图片
                let obj = that.form.Children.business_article_pic.filter(
                  (i) => i.Article_PicNumber == item.Article_PicNumber
                )[0];
                obj.Picture_Order = index + 1;
                obj.Picture_URL = item.Picture_URL;
              }
            }
          );
          that.Detail_Image.forEach((item, index) => {
            //详情图
            if (!Object.keys(item).some((item) => item.includes("_Original"))) {
              //新图片
              that.form.Children.business_article_pic.push({
                Article_PicNumber: "",
                Article_SerialNumber: that.form.Article_SerialNumber,
                Picture_Type: "1",
                Picture_Order: index + 1,
                Picture_URL: item.Picture_URL,
              });
            } else {
              //老图片
              let obj = that.form.Children.business_article_pic.filter(
                (i) => i.Article_PicNumber == item.Article_PicNumber
              )[0];
              obj.Picture_Order = index + 1;
              obj.Picture_URL = item.Picture_URL;
            }
          });
          that.form.ClassifyJSON = JSON.stringify(
            that.business_article_classify
          );
          let arr = [];
          that.business_article_classify.forEach((Array) => {
            Array.forEach((i) => {
              arr.push({
                Article_Classify_SerialNumber: "",
                Article_SerialNumber: that.form.Article_SerialNumber,
                Classify_SerialNumber: i,
                Parent_SerialNumber: Array[0],
              });
            });
          });
          that.form.Children.business_article_classify.forEach((item) => {
            if (
              !arr.some(
                (i) => i.Classify_SerialNumber == item.Classify_SerialNumber
              )
            ) {
              //一样
              item.Row_Status = "1";
            }
          });
          arr.forEach((item) => {
            if (
              !that.form.Children.business_article_classify.some(
                (i) => i.Classify_SerialNumber == item.Classify_SerialNumber
              )
            ) {
              that.form.Children.business_article_classify.push(item);
            }
          });
          that.form.Children.business_article_group =
            that.business_article_group;
          const { add, modify } = that.deal();
          let data = {};
          if (add == null) {
            data = {
              Data: JSON.stringify({
                Modify: { business_article_info: [modify] },
                Add: {
                  base_operation_log: [
                    generateLog(
                      "修改商品主数据",
                      "平台端操作",
                      "business_article_info",
                      JSON.stringify({
                        Modify: { business_article_info: [modify] },
                      })
                    ),
                  ],
                },
              }),
            };
          } else {
            data = {
              Data: JSON.stringify({
                Modify: { business_article_info: [modify] },
                Add: {
                  business_article_info: [add],
                  base_operation_log: [
                    generateLog(
                      "修改商品主数据",
                      "平台端操作",
                      "business_article_info",
                      JSON.stringify({
                        Modify: { business_article_info: [modify] },
                        Add: { business_article_info: [add] },
                      })
                    ),
                  ],
                },
              }),
            };
          }
          $.ajax({
            headers: requestHeaders(),
            url: `${BASE_URL2}/generalBusiness/generalSave`,
            type: "POST",
            data,
            success: function (res) {
              if (res.Status === "success") {
                if (that.business_supplier_article.length > 0) {
                  // that.$message.success("商品修改成功,开始配置供应商");
                  that.submitSupplier(); //提交供应商信息
                } else {
                  that.loading = false;
                  that.$message.success("提交成功");
                  window.history.go(-1);
                }
              } else {
                that.$message.error("提交失败，请稍后再试");
              }
            },
            complete: function (XMLHttpRequest) {
              that.loading = false;
              requestPretreatment(XMLHttpRequest, that);
            },
            dataType: "json",
          });
        } else {
          that.$message({
            message: sumberError,
            type: "warning",
          });
          return false;
        }
      });
    },
    submitSupplier() {
      //提交供应商
      const that = this;
      let sql = "";
      this.business_supplier_article
        .filter((i) => !i.isModify)
        .forEach((item) => {
          if (sql) {
            sql =
              sql +
              "\r\nOR business_article_info.Article_Name = '" +
              item.Article_Name +
              "'" +
              "\r\nAND business_article_specifications.Specifications_Name = '" +
              item.Specifications_Name +
              "'" +
              "\r\nAND business_article_info.Brand_SerialNumber = '" +
              item.Brand_SerialNumber +
              "'";
          } else {
            sql =
              " business_article_info.Article_Name = '" +
              item.Article_Name +
              "'" +
              "\r\nAND business_article_specifications.Specifications_Name = '" +
              item.Specifications_Name +
              "'" +
              "\r\nAND business_article_info.Brand_SerialNumber = '" +
              item.Brand_SerialNumber +
              "'";
          }
        });
      if (sql) {
        sql = `WHERE ${sql}`;
        $.ajax({
          headers: requestHeaders(),
          url: `${BASE_URL2}/generalBusiness/generalQueryBySQLSerialNumber`,
          type: "POST",
          data: {
            SQLSerialNumber: "A_business_article_specifications2",
            Condition: "",
            ExtensionCondition: window.btoa(unescape(encodeURIComponent(sql))),
          },
          success: function (Result) {
            if (Result.length > 0) {
              //执行添加
              let business_supplier_article = that.business_supplier_article;
              let base_operation_log = [];
              business_supplier_article.forEach((item) => {
                let obj = Result.filter(
                  (i) =>
                    i.Specifications_Name == item.Specifications_Name &&
                    i.Article_Name == item.Article_Name &&
                    i.Brand_SerialNumber == item.Brand_SerialNumber
                )[0];
                item.Article_SerialNumber = obj.Article_SerialNumber;
                item.Article_Specifications_SerialNumber =
                  obj.Article_Specifications_SerialNumber;
                item.Supplier_Article_SerialNumber =
                  item.Supplier_SerialNumber +
                  "-" +
                  obj.Article_Specifications_SerialNumber;
                //日志
                base_operation_log.push(
                  generateLog(
                    "添加供应商经营商品",
                    "平台端操作",
                    "business_supplier_article",
                    JSON.stringify({
                      Add: { business_supplier_article: [item] },
                    })
                  )
                );
              });
              $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalSave`,
                type: "POST",
                data: {
                  Data: JSON.stringify({
                    Add: { business_supplier_article, base_operation_log },
                  }),
                },
                success: function (res) {
                  if (res.Status === "success") {
                    //添加采购价格单
                    if (
                      business_supplier_article.filter(
                        (i) =>
                          !isNaN(i.Purchase_Unit_Price) &&
                          i.Purchase_Unit_Price > 0
                      ).length > 0
                    ) {
                      // that.$message.success("开始添加采购价格单");
                      that.submitPurchase(business_supplier_article);
                    } else if (
                      business_supplier_article.filter(
                        (i) =>
                          !isNaN(i.Sales_Unit_Price) && i.Sales_Unit_Price > 0
                      ).length > 0
                    ) {
                      //添加销售价格单
                      // that.$message.success("开始添加销售价格单");
                      that.submitSales(business_supplier_article);
                    } else if (
                      business_supplier_article.filter(
                        (i) => !isNaN(i.Quantity) && i.Quantity > 0
                      ).length > 0
                    ) {
                      // that.$message.success("开始添加每日库存");
                      that.submitStock(business_supplier_article);
                    } else if (
                      business_supplier_article.filter(
                        (i) =>
                          i.Pionts.length > 0 &&
                          !isNaN(i.Deduction_Limit) &&
                          i.Deduction_Limit > 0
                      ).length > 0
                    ) {
                      // that.$message.success("开始配置积分方案");
                      that.submitPointsConfig(business_supplier_article);
                    } else if (
                      business_supplier_article.filter(
                        (i) => i.Activity.length > 0
                      ).length > 0
                    ) {
                      // that.$message.success("开始插入活动商品");
                      that.submitActivityArticle(business_supplier_article);
                    } else {
                      that.loading = false;
                      that.$message.success("提交成功");
                      window.history.go(-1);
                    }
                  } else {
                    that.loading = false;
                    that.$message.error("提交失败，请稍后再试");
                  }
                },
                complete: function (XMLHttpRequest) {
                  requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
              });
            } else {
              that.loading = false;
              that.$message.error("未知错误");
            }
          },
          complete: function (XMLHttpRequest) {
            requestPretreatment(XMLHttpRequest);
          },
          dataType: "json",
        });
      } else {
        //添加采购价格单
        let business_supplier_article = that.business_supplier_article;
        if (
          business_supplier_article.filter(
            (i) => !isNaN(i.Purchase_Unit_Price) && i.Purchase_Unit_Price > 0
          ).length > 0
        ) {
          // that.$message.success("开始添加采购价格单");
          that.submitPurchase(business_supplier_article);
        } else if (
          business_supplier_article.filter(
            (i) => !isNaN(i.Sales_Unit_Price) && i.Sales_Unit_Price > 0
          ).length > 0
        ) {
          //添加销售价格单
          // that.$message.success("开始添加销售价格单");
          that.submitSales(business_supplier_article);
        } else if (
          business_supplier_article.filter(
            (i) => !isNaN(i.Quantity) && i.Quantity > 0
          ).length > 0
        ) {
          // that.$message.success("开始添加每日库存");
          that.submitStock(business_supplier_article);
        } else if (
          business_supplier_article.filter(
            (i) =>
              i.Pionts.length > 0 &&
              !isNaN(i.Deduction_Limit) &&
              i.Deduction_Limit > 0
          ).length > 0
        ) {
          // that.$message.success("开始配置积分方案");
          that.submitPointsConfig(business_supplier_article);
        } else if (
          business_supplier_article.filter((i) => i.Activity.length > 0)
            .length > 0
        ) {
          // that.$message.success("开始插入活动商品");
          that.submitActivityArticle(business_supplier_article);
        } else {
          that.loading = false;
          that.$message.success("提交成功");
          window.history.go(-1);
        }
      }
    },
    submitPurchase(business_supplier_article) {
      //添加采购价格单
      const that = this;
      let business_purchase_unitprice_detail = [];
      business_supplier_article
        .filter(
          (i) => !isNaN(i.Purchase_Unit_Price) && i.Purchase_Unit_Price > 0
        )
        .forEach((item) => {
          business_purchase_unitprice_detail.push({
            Purchase_Unit_Price_Detail_SerialNumber: "",
            Purchase_Unit_Price_SerialNumber: "",
            Supplier_Article_SerialNumber: item.Supplier_Article_SerialNumber,
            Brand_SerialNumber: item.Brand_SerialNumber,
            Purchase_Unit_Price: item.Purchase_Unit_Price,
          });
        });
      let business_purchase_unitprice = [
        {
          Purchase_Unit_Price_SerialNumber: "",
          Start_Date: getYMDDate(),
          End_Date: "",
          Enterprise_Info_SerialNumber: "",
          Children: {
            business_purchase_unitprice_detail,
          },
        },
      ];
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalSave`,
        type: "POST",
        data: {
          Data: JSON.stringify({ Add: { business_purchase_unitprice } }),
        },
        success: function (res) {
          if (res.Status === "success") {
            $.ajax({
              //更新今日执行单
              headers: requestHeaders(),
              url: `${BASE_URL2}/article/generateDailyArticlePurchasePrice`,
              type: "GET",
              complete: function (XMLHttpRequest) {
                if (XMLHttpRequest.status != 200) {
                  that.$message.error("每日销售价格执行单更新失败");
                }
                //添加销售价格单
                if (
                  business_supplier_article.filter(
                    (i) => !isNaN(i.Sales_Unit_Price) && i.Sales_Unit_Price > 0
                  ).length > 0
                ) {
                  // that.$message.success("开始添加销售价格单");
                  that.submitSales(business_supplier_article);
                } else if (
                  business_supplier_article.filter(
                    (i) => !isNaN(i.Quantity) && i.Quantity > 0
                  ).length > 0
                ) {
                  // that.$message.success("开始添加每日库存");
                  that.submitStock(business_supplier_article);
                } else if (
                  business_supplier_article.filter(
                    (i) =>
                      i.Pionts.length > 0 &&
                      !isNaN(i.Deduction_Limit) &&
                      i.Deduction_Limit > 0
                  ).length > 0
                ) {
                  // that.$message.success("开始配置积分方案");
                  that.submitPointsConfig(business_supplier_article);
                } else if (
                  business_supplier_article.filter((i) => i.Activity.length > 0)
                    .length > 0
                ) {
                  // that.$message.success("开始插入活动商品");
                  that.submitActivityArticle(business_supplier_article);
                } else {
                  that.loading = false;
                  that.$message.success("提交成功");
                  window.history.go(-1);
                }
              },
            });
          } else {
            that.loading = false;
            that.$message.error("采购价格单提交失败");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    submitSales(business_supplier_article) {
      //添加销售价格单
      const that = this;
      let business_sales_unitprice_detail = [];
      business_supplier_article
        .filter((i) => !isNaN(i.Sales_Unit_Price) && i.Sales_Unit_Price > 0)
        .forEach((item) => {
          business_sales_unitprice_detail.push({
            Sales_Unit_Price_Detail_SerialNumber: "",
            Sales_Unit_Price_SerialNumber: "",
            Supplier_Article_SerialNumber: item.Supplier_Article_SerialNumber,
            Brand_SerialNumber: item.Brand_SerialNumber,
            Supplier_SerialNumber: item.Supplier_SerialNumber,
            Unit_Price: item.Sales_Unit_Price,
          });
        });
      let business_sales_unitprice = [
        {
          Sales_Unit_Price_SerialNumber: "",
          Start_Date: getYMDDate(),
          End_Date: "",
          Enterprise_Info_SerialNumber: "",
          Children: {
            business_sales_unitprice_detail,
            business_sales_unitprice_storescope: [
              {
                Sales_Unit_Price_StoreScope_SerialNumber: "",
                Sales_Unit_Price_SerialNumber: "",
                Store_SerialNumber: "STORE0000000001",
              },
            ],
          },
        },
      ];
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalSave`,
        type: "POST",
        data: {
          Data: JSON.stringify({ Add: { business_sales_unitprice } }),
        },
        success: function (res) {
          if (res.Status === "success") {
            $.ajax({
              //更新今日执行单
              headers: requestHeaders(),
              url: `${BASE_URL2}/article/generateDailyArticleSalesPrice`,
              type: "GET",
              complete: function (XMLHttpRequest) {
                if (XMLHttpRequest.status != 200) {
                  that.$message.error("每日销售价格执行单更新失败");
                }
                //添加每日库存
                if (
                  business_supplier_article.filter(
                    (i) => !isNaN(i.Quantity) && i.Quantity > 0
                  ).length > 0
                ) {
                  // that.$message.success("开始添加每日库存");
                  that.submitStock(business_supplier_article);
                } else if (
                  business_supplier_article.filter(
                    (i) =>
                      i.Pionts.length > 0 &&
                      !isNaN(i.Deduction_Limit) &&
                      i.Deduction_Limit > 0
                  ).length > 0
                ) {
                  // that.$message.success("开始配置积分方案");
                  that.submitPointsConfig(business_supplier_article);
                } else if (
                  business_supplier_article.filter((i) => i.Activity.length > 0)
                    .length > 0
                ) {
                  // that.$message.success("开始插入活动商品");
                  that.submitActivityArticle(business_supplier_article);
                } else {
                  that.loading = false;
                  that.$message.success("提交成功");
                  window.history.go(-1);
                }
              },
            });
          } else {
            that.loading = false;
            that.$message.error("销售价格单提交失败");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    submitStock(business_supplier_article) {
      //添加每日库存
      const that = this;
      let business_supplier_article_stock_detail = [];
      business_supplier_article
        .filter((i) => !isNaN(i.Quantity) && i.Quantity > 0)
        .forEach((item) => {
          business_supplier_article_stock_detail.push({
            Supplier_Article_Stock_Detail_SerialNumber: "",
            Supplier_Article_Stock_SerialNumber: "",
            Supplier_Article_SerialNumber: item.Supplier_Article_SerialNumber,
            Brand_SerialNumber: item.Brand_SerialNumber,
            Quantity: item.Quantity,
          });
        });
      let business_supplier_article_stock = [
        {
          Supplier_Article_Stock_SerialNumber: "",
          Start_Date: getYMDDate(),
          End_Date: "",
          Enterprise_Info_SerialNumber: "",
          Children: {
            business_supplier_article_stock_detail,
          },
        },
      ];
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalSave`,
        type: "POST",
        data: {
          Data: JSON.stringify({ Add: { business_supplier_article_stock } }),
        },
        success: function (res) {
          if (res.Status === "success") {
            $.ajax({
              //更新今日执行单
              headers: requestHeaders(),
              url: `${BASE_URL2}/article/generateDailyInventory`,
              type: "GET",
              complete: function (XMLHttpRequest) {
                if (XMLHttpRequest.status != 200) {
                  that.$message.error("每日库存执行单更新失败");
                }
                //添加积分配置
                if (
                  business_supplier_article.filter(
                    (i) =>
                      i.Pionts.length > 0 &&
                      !isNaN(i.Deduction_Limit) &&
                      i.Deduction_Limit > 0
                  ).length > 0
                ) {
                  // that.$message.success("开始配置积分方案");
                  that.submitPointsConfig(business_supplier_article);
                } else if (
                  business_supplier_article.filter((i) => i.Activity.length > 0)
                    .length > 0
                ) {
                  // that.$message.success("开始插入活动商品");
                  that.submitActivityArticle(business_supplier_article);
                } else {
                  that.loading = false;
                  that.$message.success("提交成功");
                  window.history.go(-1);
                }
              },
            });
          } else {
            that.loading = false;
            that.$message.error("每日库存单提交失败");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    submitPointsConfig(business_supplier_article) {
      //添加积分配置
      const that = this;
      let business_points_detail_config = [];
      business_supplier_article
        .filter(
          (i) =>
            i.Pionts.length > 0 &&
            !isNaN(i.Deduction_Limit) &&
            i.Deduction_Limit > 0
        )
        .forEach((item) => {
          business_points_detail_config.push({
            Points_Detail_Config_SerialNumber: "",
            Supplier_Article_SerialNumber: item.Supplier_Article_SerialNumber,
            Gift_Point: item.Pionts.some((i) => i == "Gift") ? "0" : "1",
            Sales_Point: item.Pionts.some((i) => i == "Sales") ? "0" : "1",
            Cash_Point: item.Pionts.some((i) => i == "Cash") ? "0" : "1",
            Activit_Point: item.Pionts.some((i) => i == "Activit") ? "0" : "1",
            Deduction_Type: item.Deduction_Type,
            Deduction_Limit: item.Deduction_Limit,
            Combination: "1",
          });
        });
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalSave`,
        type: "POST",
        data: {
          Data: JSON.stringify({ Add: { business_points_detail_config } }),
        },
        success: function (res) {
          if (res.Status === "success") {
            //插入活动商品
            if (
              business_supplier_article.filter((i) => i.Activity.length > 0)
                .length > 0
            ) {
              // that.$message.success("开始插入活动商品");
              that.submitActivityArticle(business_supplier_article);
            } else {
              that.loading = false;
              that.$message.success("提交成功");
              window.history.go(-1);
            }
          } else {
            that.$message.error("积分配置提交失败");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    submitActivityArticle(business_supplier_article) {
      //插入活动商品
      const that = this;
      let add_business_activity_article = [],
        modify_business_activity_article = [];
      business_supplier_article.forEach((item) => {
        item.Activity.filter(
          (i) =>
            i.Activity_SerialNumber &&
            !isNaN(i.Activity_Unit_Price) &&
            i.Activity_Unit_Price > 0
        ).forEach((ite) => {
          if (!Object.keys(ite).some((item) => item.includes("_Original"))) {
            add_business_activity_article.push({
              Activity_Article_SerialNumber: "",
              Activity_SerialNumber: ite.Activity_SerialNumber,
              Supplier_Article_SerialNumber: item.Supplier_Article_SerialNumber,
              Article_SerialNumber: "",
              Article_Specifications_SerialNumber:
                item.Article_Specifications_SerialNumber,
              Activity_Unit_Price: ite.Activity_Unit_Price,
            });
          } else {
            modify_business_activity_article.push(ite);
          }
        });
      });
      console.log(add_business_activity_article);
      let base_operation_log = [
        generateLog(
          "更新活动商品",
          "平台端操作",
          "business_activity_article",
          JSON.stringify({
            Add: {
              business_activity_article: add_business_activity_article,
            },
            Modify: {
              business_activity_article: modify_business_activity_article,
            },
          })
        ),
      ];
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalSave`,
        type: "POST",
        data: {
          Data: JSON.stringify({
            Modify: {
              business_activity_article: modify_business_activity_article,
            },
            Add: {
              business_activity_article: add_business_activity_article,
              base_operation_log,
            },
          }),
        },
        success: function (res) {
          if (res.Status === "success") {
            that.$message.success("提交成功");
            window.history.go(-1);
          } else {
            that.$message.error("插入活动商品提交失败");
          }
        },
        complete: function (XMLHttpRequest) {
          that.loading = false;
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    deal() {
      const add = deepClone(this.form);
      const modify = deepClone(this.form);

      let add_business_article_pic = [],
        modify_business_article_pic = [];
      let add_business_article_specifications = [],
        modify_business_article_specifications = [];
      let add_business_article_classify = [],
        modify_business_article_classify = [];
      let add_business_article_group = [],
        modify_business_article_group = [];

      for (const i in modify.Children.business_article_pic) {
        const obj = modify.Children.business_article_pic[i];
        if (!Object.keys(obj).some((item) => item.includes("_Original"))) {
          add_business_article_pic.push(obj);
        } else {
          modify_business_article_pic.push(obj);
        }
      }
      for (const i in modify.Children.business_article_specifications) {
        const obj = modify.Children.business_article_specifications[i];
        if (!Object.keys(obj).some((item) => item.includes("_Original"))) {
          add_business_article_specifications.push(obj);
        } else {
          modify_business_article_specifications.push(obj);
        }
      }

      for (const i in modify.Children.business_article_classify) {
        const obj = modify.Children.business_article_classify[i];
        if (!Object.keys(obj).some((item) => item.includes("_Original"))) {
          add_business_article_classify.push(obj);
        } else {
          modify_business_article_classify.push(obj);
        }
      }

      for (const i in modify.Children.business_article_group) {
        const obj = modify.Children.business_article_group[i];
        if (!Object.keys(obj).some((item) => item.includes("_Original"))) {
          add_business_article_group.push(obj);
        } else {
          const { add, modify } = this.deal1(obj);
          modify_business_article_group.push(modify);
          if (add != null) {
            add_business_article_group.push(add);
          }
        }
      }

      add.Children.business_article_pic = add_business_article_pic;
      modify.Children.business_article_pic = modify_business_article_pic;

      add.Children.business_article_specifications =
        add_business_article_specifications;
      modify.Children.business_article_specifications =
        modify_business_article_specifications;

      add.Children.business_article_classify = add_business_article_classify;
      modify.Children.business_article_classify =
        modify_business_article_classify;

      add.Children.business_article_group = add_business_article_group;
      modify.Children.business_article_group = modify_business_article_group;

      console.log({ add, modify });

      if (
        add_business_article_pic.length == 0 &&
        add_business_article_specifications.length == 0 &&
        add_business_article_classify.length == 0 &&
        add_business_article_group.length == 0
      ) {
        return { add: null, modify };
      }
      return { add, modify };
    },
    deal1(obj) {
      //孙表
      const add = deepClone(obj);
      const modify = deepClone(obj);

      let add_business_article_group_detail = [],
        modify_business_article_group_detail = [];
      for (const i in modify.Children.business_article_group_detail) {
        const obj = modify.Children.business_article_group_detail[i];
        if (!Object.keys(obj).some((item) => item.includes("_Original"))) {
          add_business_article_group_detail.push(obj);
        } else {
          modify_business_article_group_detail.push(obj);
        }
      }

      add.Children.business_article_group_detail =
        add_business_article_group_detail;
      modify.Children.business_article_group_detail =
        modify_business_article_group_detail;

      if (add_business_article_group_detail.length == 0) {
        return { add: null, modify };
      }
      return { add, modify };
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    add_article_specifications() {
      //添加规格
      this.business_article_group.push({
        Specification_Group_Name: "",
        Children: {
          business_article_group_detail: [
            {
              id: createUniqueString(),
              Specification_Group_Detail_Name: "",
            },
          ],
        },
      });
      // this.form.Children.business_article_specifications.push({
      //     Article_Specifications_SerialNumber: '',//规格主键
      //     Article_SerialNumber: this.form.Article_SerialNumber,
      //     Specifications_Name: '',//规格名称
      //     Unit_Price: this.form.Unify_Unit_Price == '0' ? 0 : this.form.Unit_Price,//吊牌价
      //     SKU_Quantity: '',//SKU数量
      //     Size:'',
      //     Weight: '',//重量
      //     Weight_Unit: '',//单位
      //     JDCOM_Unit_Price: '',
      //     JDCOM_URL: '',
      //     Package_Quantity: '',//包装数量
      //     SKU_Package_Size: '',//包装尺寸
      //     Carton_Quantity: '',//大包装数量
      //     Children_Specifications_SerialNumber: '',
      //     Other:[{
      //         Supplier_SerialNumber:'',
      //         Sales_Unit_Price:'',
      //         Purchase_Unit_Price:'',
      //         Quantity:'',
      //         Pionts:[],
      //         Deduction_Type:'1',
      //         Deduction_Limit:'100',
      //         Activity:[{
      //             Activity_SerialNumber:'',
      //             Activity_Unit_Price:'',
      //         }]
      //     }]
      // })
    },
    remove_article_specifications() {
      //删除规格
      if (
        this.business_article_group.filter((item) => item.Row_Status != "1")
          .length > 1
      ) {
        //必须至少剩1个
        let i =
          this.business_article_group.filter((item) => item.Row_Status != "1")
            .length - 1;
        let obj = this.business_article_group.filter(
          (item) => item.Row_Status != "1"
        )[i];
        if (!Object.keys(obj).some((item) => item.includes("_Original"))) {
          this.business_article_group.pop();
        } else {
          this.$confirm("该操作将删除此规格,是否继续?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              this.business_article_group.filter(
                (item) => item.Row_Status != "1"
              )[i].Row_Status = "1";
            })
            .catch(() => {
              this.$message({
                type: "warning",
                message: "已取消删除",
              });
            });
        }
      } else {
        this.$message({
          message: "不能在删除了",
          type: "warning",
        });
      }
      // if (this.form.Children.business_article_specifications.filter(item => item.Row_Status != '1').length > 1) {//必须至少剩1个
      //     let i = this.form.Children.business_article_specifications.filter(item => item.Row_Status != '1').length - 1
      //     let obj = this.form.Children.business_article_specifications.filter(item => item.Row_Status != '1')[i]
      //     if (!Object.keys(obj).some(item => item.includes('_Original'))) {
      //         this.form.Children.business_article_specifications.pop()
      //     } else {
      //         this.$confirm('该操作将删除此规格,是否继续?', '提示', {
      //             confirmButtonText: '确定',
      //             cancelButtonText: '取消',
      //             type: 'warning',
      //         }).then(() => {
      //             this.form.Children.business_article_specifications.filter(item => item.Row_Status != '1')[i].Row_Status = '1'
      //         }).catch(() => {
      //             this.$message({
      //                 type: 'warning',
      //                 message: '已取消删除'
      //             });
      //         });
      //     }
      // } else {
      //     this.$message({
      //         message: '不能在删除了',
      //         type: 'warning'
      //     })
      // }
    },
    handleImgClick(formName) {
      //点击查看图片
      this.$refs[formName][0].showViewer = true;
    },
    add_Other(obj) {
      obj.Other.push({
        Supplier_SerialNumber: "",
        Sales_Unit_Price: "",
        Purchase_Unit_Price: "",
        Quantity: "",
        Pionts: [],
        Deduction_Type: "1",
        Deduction_Limit: "100",
        Activity: [
          {
            Activity_SerialNumber: "",
            Activity_Unit_Price: "",
          },
        ],
      });
    },
    remove_Other(obj) {
      if (obj.Other.length > 0) {
        obj.Other.pop();
      } else {
        this.$message({
          message: "不能在删除了",
          type: "warning",
        });
      }
    },
    add_Activity(obj) {
      obj.Activity.push({
        Activity_SerialNumber: "",
        Activity_Unit_Price: "",
      });
    },
    remove_Activity(obj) {
      if (obj.Activity.length > 0) {
        obj.Activity.pop();
      } else {
        this.$message({
          message: "不能在删除了",
          type: "warning",
        });
      }
    },
    add_article_group_detail(item) {
      item.Children.business_article_group_detail.push({
        id: createUniqueString(),
        Specification_Group_Detail_Name: "",
      });
    },
    remove_article_group_detail(id, item, ite) {
      if (!Object.keys(ite).some((item) => item.includes("_Original"))) {
        item.Children.business_article_group_detail =
          item.Children.business_article_group_detail.filter(
            (it, i) => i != id
          );
      } else {
        this.$confirm("是否要删除规格值?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            item.Children.business_article_group_detail.filter(
              (it, i) => i == id
            )[0].Row_Status = "1";
          })
          .catch(() => {});
      }
    },
    RemoveImage(formName, index, item) {
      //删除图片
      if (!Object.keys(item).some((item) => item.includes("_Original"))) {
        let removeimage = this[formName].filter((i) => i.Row_Status == "1");
        let image = this[formName].filter((i) => i.Row_Status != "1");
        image.splice(index, 1);
        this[formName] = [...image, ...removeimage];
      } else {
        this.$confirm("是否要删除该图片?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this[formName].filter((i) => i.Row_Status != "1")[
              index
            ].Row_Status = "1";
          })
          .catch(() => {});
      }
    },
    sortable(that, container, element, jsonarray, className, callback) {
      //拖拽class配置
      var $ul = that.$el.querySelector(container);
      $ul.addEventListener("selectstart", function (e) {
        e.preventDefault();
      });
      this[className] = Sortable.create($ul, {
        handle: element,
        draggable: element,
        animation: 150,
        onUpdate: (event) => {
          let newIndex = event.newIndex,
            oldIndex = event.oldIndex;
          ($li = $ul.children[newIndex]), ($oldLi = $ul.children[oldIndex]);
          //先删除移动的节点, 再插入移动的节点到原有节点，还原了移动的操作
          $ul.removeChild($li);
          if (newIndex > oldIndex) {
            $ul.insertBefore($li, $oldLi);
          } else {
            $ul.insertBefore($li, $oldLi.nextSibling);
          }
          //通过改变vue遍历数组移动节点
          let removearray = this[jsonarray].filter((i) => i.Row_Status == "1");
          let array = this[jsonarray].filter((i) => i.Row_Status != "1");
          let item = array[oldIndex];
          array.splice(oldIndex, 1);
          array.splice(newIndex, 0, item);
          this[jsonarray] = [...array, ...removearray];
          if (callback) callback(newIndex, oldIndex);
        },
      });
      this[className].option("disabled", true);
    },
  },
});
